﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="~/css/framework-font.css" rel="stylesheet" />
    <link href="~/css/framework-theme.css" rel="stylesheet" />
    <script src="~/lib/jquery/1.12.4/jquery.min.js"></script>
    <script src="~/lib/jquery-ui/jquery-ui.min.js"></script>
    <script src="~/lib/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="~/lib/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/lib/layout/jquery.layout.js"></script>
    <script src="~/lib/wdtree/tree.js"></script>
    <link href="~/lib/wdtree/tree.css" rel="stylesheet" />
    <link href="~/lib/jqgrid/5.3.0/css/ui.jqgrid-bootstrap.css" rel="stylesheet" />
    <script src="~/lib/jqgrid/5.3.0/js/jquery.jqGrid.js"></script>
    <script src="~/lib/jqgrid/5.3.0/i18n/grid.locale-cn.js"></script>
    <link href="~/css/framework-ui.css" rel="stylesheet" />
    <script src="~/js/framework-ui.js"></script>
    <style>
        html, body {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
    <script>
        $(function () {
            $('#layout').layout();
            treeView();
            gridList();
        });
        function treeView() {
            $("#dictTree").treeview({
                url: "/SystemManage/Dict/GetTreeJson",
                onnodeclick: function (item) {
                    $("#txt_keyword").val('');
                    $('#btn_search').trigger("click");
                }
            });
        }
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                height: $(window).height() - 97,
                colModel: [
                    { label: "主键", name: "Id", hidden: true, key: true },
                    { label: '名称', name: 'ItemName', width: 150, align: 'left' },
                    { label: '编号', name: 'ItemCode', width: 150, align: 'left' },
                    { label: '排序', name: 'SortCode', width: 80, align: 'center' },
                    {
                        label: "默认", name: "IsDefault", width: 60, align: "center",
                        formatter: function (cellvalue) {
                            return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    {
                        label: '创建时间', name: 'CreatedTime', width: 80, align: 'center',
                        formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                    },
                    {
                        label: "有效", name: "EnabledMark", width: 60, align: "center",
                        formatter: function (cellvalue) {
                            return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: "备注", name: "Description", index: "F_Description", width: 200, align: "left", sortable: false }
                ]
            });
            $("#btn_search").click(function () {
                $gridList.jqGrid('setGridParam', {
                    url: "/SystemManage/DictItem/GetGridJson",
                    postData: { dictId: $("#dictTree").getCurrentNode().id, keyword: $("#txt_keyword").val() },
                }).trigger('reloadGrid');
            });
        }
        function btn_add() {
            var dictId = $("#dictTree").getCurrentNode().id;
            var dictName = $("#dictTree").getCurrentNode().text;
            if (!dictId) {
                return false;
            }
            $.modalOpen({
                id: "Form",
                title: dictName + " 》新增字典项目",
                url: "/SystemManage/DictItem/Form?dictId=" + dictId,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_edit() {
            var dictId = $("#dictTree").getCurrentNode().id;
            var dictName = $("#dictTree").getCurrentNode().text;            
            var keyValue = $("#gridList").jqGridRowValue().Id;
            $.modalOpen({
                id: "Form",
                title: dictName + " 》编辑字典项目",
                url: "/SystemManage/DictItem/Form?keyValue=" + keyValue+"&dictId="+dictId,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_details() {
            var dictId = $("#dictTree").getCurrentNode().id;
            var dictName = $("#dictTree").getCurrentNode().text;
            var keyValue = $("#gridList").jqGridRowValue().Id;
            $.modalOpen({
                id: "Details",
                title: dictName + " 》编辑字典项目",
                url: "/SystemManage/DictItem/Details?keyValue=" + keyValue + "&dictId=" + dictId,
                width: "450px",
                height: "350px",
                btn: null
            });
        }
        function btn_delete() {
            var keyValue = $("#gridList").jqGridRowValue().Id;
            $.deleteForm({
                url: "/SystemManage/DictItem/DeleteForm",
                param: { keyValue: keyValue },
                success: function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_itemstype() {
            $.modalOpen({
                id: "ItemsType",
                title: "字典管理",
                url: "/SystemManage/Dict/Index",
                width: "70%",
                height: "90%",
                btn: null,
            });
        }
    </script>
    <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
        <div class="ui-layout-west">
            <div id="dictTree"></div>
        </div>
        <div class="ui-layout-center">
            <div class="topPanel">
                <div class="toolbar">
                    <div class="btn-group">
                        <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                    <div class="btn-group">
                        <a id="NF-Add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增字典项目</a>
                        <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu pull-right">
                            <li><a id="NF-Dict" authorize="yes" onclick="btn_itemstype()" href="javascript:void()">字典管理</a></li>
                        </ul>
                    </div>
                    <div class="operate">
                        <ul class="nav nav-pills">
                            <li class="first">已选中<span>1</span>项</li>
                            <li><a id="NF-Edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>编辑字典项目</a></li>
                            <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-pencil-square-o"></i>查看字典项目</a></li>
                            <li><a id="NF-Delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除字典项目</a></li>
                        </ul>
                        <a href="javascript:;" class="close"></a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
                <div class="search">
                    <table>
                        <tr>
                            <td>
                                <div class="input-group">
                                    <input id="txt_keyword" type="text" class="form-control" placeholder="名称/编号" style="width: 200px;">
                                    <span class="input-group-btn">
                                        <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                                    </span>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridList"></table>
            </div>
        </div>
    </div>
</body>
</html>
